<?php

class Sistema_Form_Subpagina extends Zend_Form {

    public function init() {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;

        $this->setName('form_' . $controller);
        $this->setAttrib('class', 'formCtrl');

        $id = $front->getRequest()->getParam('id', 0);
        $pag_id = $front->getRequest()->getParam('pag_id',0);
        
        $url .= '/index/pag_id/'.$pag_id;
       
        
        $el = new Zend_Form_Element_Hidden('SPG_ID', array('disableLoadDefaultDecorators' => true));
        $el->addDecorators(array(array('ViewHelper'), array('Errors')))
                ->addFilter('Int');
        $this->addElement($el);

        $el = new Zend_Form_Element_Text('SPG_NOM');
        $el->setLabel('Título')->setRequired(true);
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('SPG_NOMSUB');
        $el->setLabel('Subtítulo');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('SPG_TXT');
        $el->setLabel('Texto');
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('SPG_CORBAC');
        $el->setLabel('Cor de Fundo')->setRequired(true);
        $el->setAttrib('class', 'cor');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_File('SPG_FILE');
        $el->setLabel('Imagem')
	->addValidator('Extension', false, array('jpg','jpeg', 'png', 'gif'));
        $this->addElement($el);
        $img = glob('public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*');
        if(count($img) > 0)
        foreach($img as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_Text('SPG_ORD');
        $el->setLabel('Ordem')->setRequired(true);
        $el->setAttrib('required', '');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('SPG_STA',array('checked'=>'checked'));
        $el->setLabel('Ativo');
        $this->addElement($el);
        
        $btn = new Zend_Form_Element_Submit('Salvar', array('disableLoadDefaultDecorators' => true));
        $btn->setLabel('Salvar');
        $btn->addDecorators(array(array('ViewHelper'), array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);

        $btn = new Zend_Form_Element_Button('Cancelar', array('disableLoadDefaultDecorators' => true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="' . $url . '" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
    }

}
